<?php
/**
 *
 * @Author nikm $
 *
 * @Date 2011-12-29 $
 */

if(!defined('FROM_INDEX')) exit('Invalid request');

date_default_timezone_set('Asia/Shanghai');

define('STAGE', 'prod');
define('ADODB_PATH', ROOT_PATH.'lib/adodb5/');

// base url
if(array_key_exists('SCRIPT_URI', $_SERVER))
{
	$uri = $_SERVER["SCRIPT_URI"];
	$BASE_URL = parse_url($uri, PHP_URL_SCHEME)."://".parse_url($uri, PHP_URL_HOST);
	
	if(!defined('BASE_URL'))
	{
		define('BASE_URL',  "http://".parse_url($uri, PHP_URL_HOST)."/movie/");
	}

	if(!defined('BASE_URL_HTTPS'))
	{
		define('BASE_URL_HTTPS',  "https://".parse_url($uri, PHP_URL_HOST)."/movie/");
	}
}

function load_setting($filename, $name='')
{
	$file = ROOT_PATH.'config/'.$filename.'.php';
	
	if(!is_file($file))
	{
		exit("Setting file '".$file."' does not exists!");
	}
	
	include $file;
	
	if(is_array($setting))
	{
		if($name && isset($setting[$name]))
		{
			if(is_array($setting[$name]))
			{
				foreach($setting[$name] as $k=>$v)
				{
					if(!defined(strtoupper($k))) define(strtoupper($k), $v);
				}
			}
			else
			{
				if(!defined(strtoupper($name))) define(strtoupper($name), $setting[$name]);
			}
		}
		else
		{
			foreach($setting as $k=>$v)
			{
				if(is_array($v))
				{
					foreach($v as $sk=>$sv)
					{
						if(!defined(strtoupper($sk))) define(strtoupper($sk), $sv);
					}
				}
				else
				{
					if(!defined(strtoupper($k))) define(strtoupper($k), $v);
				}
			}
		}
	}
	
	return '';
}